package com.xyzwps.server.paimon.error

import org.springframework.graphql.execution.ErrorType
import org.springframework.http.HttpStatus

class AppException(
    val status: HttpStatus,
    val code: Int,
    message: String
) : RuntimeException(message) {

    // TODO: message 有点拖沓了。再想想 i18n 怎么搞

    val errorType: ErrorType = when (status) {
        HttpStatus.BAD_REQUEST -> ErrorType.BAD_REQUEST
        HttpStatus.UNAUTHORIZED -> ErrorType.UNAUTHORIZED
        HttpStatus.FORBIDDEN -> ErrorType.FORBIDDEN
        HttpStatus.NOT_FOUND -> ErrorType.NOT_FOUND
        else -> ErrorType.INTERNAL_ERROR
    }
}